package com.cml.dm.admin.service.impl;

import com.cml.dm.admin.mapper.DmExeLoggerMapper;
import com.cml.dm.admin.mapper.DmMetadataMapper;
import com.cml.dm.admin.service.DmContextInitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class DmContextSQLInitService implements DmContextInitService {
    @Resource
    private DmExeLoggerMapper dmExeLoggerMapper;

    @Resource
    private DmMetadataMapper dmMetadataMapper;

    public void init() {
        log.info("sql初始化开始");
        log.info("开始检查数据库表是否存在");
        try {
            dmExeLoggerMapper.selectById(Long.MAX_VALUE);
        }catch (Exception e) {
            if(e.getMessage().contains("doesn't exist")){
                log.info("dmExeLogger表未创建");
                dmExeLoggerMapper.createNewTable();
            }
        }
        try {
            dmMetadataMapper.selectById(Long.MAX_VALUE);
        }catch (Exception e) {
            if(e.getMessage().contains("doesn't exist")){
                log.info(" dmMetadata表未创建");
                dmMetadataMapper.createNewTable();
            }
        }

        log.info("sql初始化结束");
    }
}
